package com.project.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitConfig {
      @Autowired
      CachingConnectionFactory connectionFactory;
      
      //rabbitmq模板
      @Bean(value = "rabbitTemplate")
      public RabbitTemplate rabbitTemplate() {
            return new RabbitTemplate(connectionFactory);
      }
      //交换机与队列绑定
      
      @Bean
      public DirectExchange directExchangeUser(){
            return new DirectExchange("directExchangeUser");
      }
      @Bean
      public Queue authentication() {
            return new Queue("authentication");
      }
      //交换机和队列绑定
      @Bean
      public Binding directExchangeToQueueOne(Queue authentication, DirectExchange directExchangeUser){
            return   BindingBuilder.bind(authentication).to(directExchangeUser).with("rabbit.authentication");
      }
      //创建队列
      //审核的mq
      //下单
      @Bean
      public Queue addOrder() {
            return new Queue("addOrder");
      }
      @Bean
      public Binding directExchangeToAddOrder(Queue addOrder, DirectExchange directExchange) {
            return BindingBuilder.bind(addOrder).to(directExchange).with("addOrder");
      }
      //退货
      @Bean
      public Queue returnOrder() {
            return new Queue("returnOrder");
      }
      @Bean
      public Binding directExchangeToReturnOrder(Queue returnOrder, DirectExchange directExchange) {
            return BindingBuilder.bind(returnOrder).to(directExchange).with("returnOrder");
      }
      //充值
      @Bean
      public Queue addMoney() {
            return new Queue("addMoney");
      }
      @Bean
      public Binding directExchangeToReturnAddMoney(Queue addMoney, DirectExchange directExchange) {
            return BindingBuilder.bind(addMoney).to(directExchange).with("addMoney");
      }
      //后端mq
      //美化的商品
      @Bean
      public Queue beautifyProduct() {
            return new Queue("beautifyProduct");
      }
      @Bean
      public Binding directExchangeToBeautifyProduct(Queue beautifyProduct, DirectExchange directExchange) {
            return BindingBuilder.bind(beautifyProduct).to(directExchange).with("beautifyProduct");
      }
      //创建交换机
      @Bean
      public DirectExchange directExchange() {
            return new DirectExchange("webOne");
      }


      //下单
      @Bean
      public Queue addOrderEnd() {
            return new Queue("addOrderEnd");
      }
      @Bean
      public Binding directExchangeToAddOrderEnd(Queue addOrderEnd, DirectExchange directExchange) {
            return BindingBuilder.bind(addOrderEnd).to(directExchange).with("addOrderEnd");
      }
      
      
      
}
